# -*- coding: utf-8 -*-
# @Time    : 2020/6/20 下午1:20
# @Author  : caotian
# @FileName: lenettrain1.py
# @Software: PyCharm
import sys
import os
curpath=os.path.abspath(os.curdir)
sys.path.append(curpath)
import lenetmodel as lm
import numpy as np
import paddle.fluid as fluid

x=np.random.randn(*[3,1,28,28])
x=x.astype('float32')
with fluid.dygraph.guard():
    m=lm.LeNet(num_classes=10)
    print(m.sublayers())
    x=fluid.dygraph.to_variable(x)
    for item in m.sublayers():
        try:
            x=item(x)
        except:
            x=fluid.layers.reshape(x,[x.shape[0],-1])
            x=item(x)
        if len(item.parameters())==2:
            print(item.full_name(),x.shape,item.parameters()[0].shape,item.parameters()[1].shape)
        else:
            print(item.full_name(),x.shape)
